package com.sgb.kjwl.view.widget.pick;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutPickDetailInfoBinding;
import com.sgb.kjwl.model.entity.pick.TenderDictEntity3;
import com.sgb.kjwl.model.entity.pick.TenderInfoBasicEntity3;
import com.sgb.kjwl.view.ui.adapter.pick.PickDetailDictAdapter3;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author:         张驰
 * @CreateDate:     006
 * @UpdateUser:     张驰
 * @UpdateDate:     2020年09月24
 * @UpdateRemark:   报名详情页中招标信息模块布局
 * @Version:        招采 2.7.2
 */
public class PickDetailInfoView extends RelativeLayout {

    private Context mContext;
    private LayoutPickDetailInfoBinding binding;
    private PickDetailDictAdapter3 pickDetailDictAdapter3;
    private List<TenderInfoBasicEntity3> tenderInfoBasicEntity3List = new ArrayList<>();

    public PickDetailInfoView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public PickDetailInfoView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }

    public PickDetailInfoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.layout_pick_detail_info, this, true);
        if (pickDetailDictAdapter3 == null) {
            pickDetailDictAdapter3 = new PickDetailDictAdapter3(mContext, tenderInfoBasicEntity3List);
        }

        binding.pickRecycler.setSectionedRecyclerViewAdapter(pickDetailDictAdapter3);
        binding.pickRecycler.setLoadingMoreEnabled(false);
        binding.pickRecycler.setPullRefreshEnabled(false);
        GridLayoutManager rightManager = new GridLayoutManager(mContext, 1);
        binding.pickRecycler.setLayoutManager(rightManager);
        binding.pickRecycler.setAdapter(pickDetailDictAdapter3);
    }

    public void showInfoView(List<TenderInfoBasicEntity3> tenderInfoBasicEntity3List) {
        if (tenderInfoBasicEntity3List == null) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }
        if (tenderInfoBasicEntity3List.size() == 0) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }

        List<TenderInfoBasicEntity3> tempList = new ArrayList<>();
        if(tenderInfoBasicEntity3List.size() > 0){
            for (TenderInfoBasicEntity3 entity3 : tenderInfoBasicEntity3List) {
                List<TenderDictEntity3> datas = entity3.getDatas();
                List<TenderDictEntity3> tempChildList = new ArrayList<>();
                if(datas != null && datas.size() > 0){
                    for (TenderDictEntity3 data : datas) {
                        if(!TextUtils.isEmpty(data.getName()) || !TextUtils.isEmpty(data.getValue())){
                            tempChildList.add(data);
                        }
                    }
                }
                entity3.setDatas(tempChildList);
                tempList.add(entity3);
            }
        }

        pickDetailDictAdapter3.setData(tenderInfoBasicEntity3List);
    }
}
